package dog.gui;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.*;

import containers.Message;

import dog.gui.appointmentView.IndexedJPanel;
import dog.model.Model;

public class NewsPanel extends JScrollPane
	{
	Model model;
	JPanel panel;
	public NewsPanel(Model model)
		{
		super();
		System.out.println("New MessagePanel");
		this.setPreferredSize(new Dimension(192,400));
		panel = new JPanel();
		this.setViewportView(panel);
		this.model=model;
		//panel.setPreferredSize(new Dimension(180,400));
		panel.setLayout(new GridBagLayout());
		//panel.add(new JLabel("Test"));
		}
	public void addMessage(MessagePanel mp)
		{
		GridBagConstraints c = new GridBagConstraints();
		c.gridy=mp.getMessage().messageID;
		System.out.println("Message added AAAA");
		JPanel kuk = new JPanel();
		//kuk.add(new JLabel("Test"));
		panel.add(mp.getComponent(),c);
		//panel.add(new MessagePanel(new Message(0,0,0,0,0,0, "", null),model,this),c);
		//panel.add(kuk,c);
		panel.validate();
		}
	public void removeMessage(MessagePanel mp)
		{
		System.out.println("Message removed BBBB");
		
		Component[] c = panel.getComponents();
		for(int i=0; i<c.length; i++)
			{
			if(c[i] instanceof IndexedJPanel)
				{
				System.out.println("CCCC");
				if(((IndexedJPanel)c[i]).getIndex()==mp.getMessage().messageID)
					{
					System.out.println("DDDD");
					panel.remove(c[i]);
					}
				}
			}
		this.validate();
		}
	}
